home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: very simple newbie question
- Date: Wed, 28 Feb 96 18:52:46 GMT
- Organization: none
- Message-ID: <825533566snz@genesis.demon.co.uk>
- References: <robertk-2802960012350001@robertk.accessone.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <robertk-2802960012350001@robertk.accessone.com>
- robertk@accessone.com "robertk" writes:
-
- > #include <stdio.h>
- > main()
- > {
- > char s[10];
- > scanf("%s/n",s);
-
- I assume you meant \n ^
-
- > printf("%s",s);
- > }
- >
- > when i run this and input:
- >
- > robert <enter> --->when i hit the enter key the cursor
- > drops down a line and sits ther flashing
- > waiting for me to enter another character
- > like x before it will throw me back to the
- > ide. upon returning to the screen i see
- > robert
- > x
- > robert
- >
- > i thought scanf() ignored whitespace?
-
- When it sees a white-space character (such as '\n') in the format string it
- *skips* white-space. That means it continues to read characters until it
- encounters one that is not white-space or it encounters EOF. Therefore the
- scanf will continue to execute and read characters from the input stream
- until you type something that isn't purely white-space.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-